package com.inossem.warehousestorage_inossem.utils;

import android.content.Context;
import android.graphics.Bitmap;
import android.os.Environment;

import com.inossem.utils.base.Utils;

import java.io.File;
import java.io.IOException;

/**
 * Created by leij on 2017/11/29.
 */

public class CompressUtils {

    private static final String COMPRESS_FILE_ROOT_PATH = "Inossem_COMPRESS_FILE"; // 压缩文件根目录

    private static final int WIDTH_LARGE = 360;

    private static final int HEIGHT_LARGE = 640;

    private static final int WIDTH_NORMAL = 270;

    private static final int HEIGHT_NORMAL = 480;

    private static final int WIDTH_SMALL = 90;

    private static final int HEIGHT_SMALL = 160;

    static String getRootPath() {
        String rootPath = Environment.getExternalStorageDirectory().getAbsolutePath()
                + File.separator + COMPRESS_FILE_ROOT_PATH;
        return rootPath;
    }

    public static File compressImageToFileNormal(Context context, File file) {
        try {
            return Utils.compressImageToFile(context, file, WIDTH_NORMAL, HEIGHT_NORMAL, Bitmap.CompressFormat.WEBP, 100, getRootPath());
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static File compressImageToFileSMALL(Context context, File file) {
        try {
            return Utils.compressImageToFile(context, file, WIDTH_SMALL, HEIGHT_SMALL, Bitmap.CompressFormat.WEBP, 100, getRootPath());
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static File compressImageToFileLARGE(Context context, File file) {
        try {
            return Utils.compressImageToFile(context, file, WIDTH_LARGE, HEIGHT_LARGE, Bitmap.CompressFormat.WEBP, 100, getRootPath());
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

}
